
package uestc.bitman.edxapp.player;

import uestc.bitman.edxapp.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

public class VideoSelectListAdapter extends BaseAdapter {

    private List<VideoDesciptor> mVideos;

    private LayoutInflater mInflater;

    private OnClickListener mDownloadClickListener;

    public VideoSelectListAdapter(final Context context, final List<VideoDesciptor> videos,OnClickListener listener) {

        mInflater = LayoutInflater.from(context);
        this.mVideos = videos;

        mDownloadClickListener =listener;
    }

    @Override
    public int getCount() {
        return mVideos.size();
    }

    @Override
    public Object getItem(int pos) {
        return mVideos.get(pos);
    }

    @Override
    public long getItemId(int pos) {
        return pos;
    }

    @Override
    public View getView(int pos, View convertView, ViewGroup parent) {

        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.video_list_item, null);
            TextView videoNameView = (TextView) convertView.findViewById(R.id.video_name_view);
            videoNameView.setText(mVideos.get(pos).getTitle());
            ImageView imgDownload = (ImageView) convertView.findViewById(R.id.download_img_view);
            imgDownload.setOnClickListener(mDownloadClickListener);
            imgDownload.setTag(pos);
            convertView.setTag(videoNameView);
        }
        return convertView;
    }
}
